Skip to content

Use runspace to acquire version to avoid CLM issues - #1869

Merged
Aditya Patwardhan (adityapatwardhan) merged 2 commits into
masterfrom
CLM2
Sep 5, 2025
Merged

Use runspace to acquire version to avoid CLM issues#1869
Aditya Patwardhan (adityapatwardhan) merged 2 commits into
masterfrom
CLM2

Conversation

@adityapatwardhan

Copy link
Copy Markdown
Member

PR Summary

This pull request introduces a new helper method to retrieve the user agent string and simplifies how the PowerShell version is determined for user agent construction. The changes improve maintainability and reliability by reducing the use of PowerShell scripts and exposing a direct way to access the user agent string.

User agent string handling:

  • Added a new static method GetUserString to InternalHooks that returns the user agent string via UserAgentInfo.UserAgentString().

PowerShell version detection:

  • Updated the static constructor of UserAgentInfo to retrieve the PowerShell version using Runspace.DefaultRunspace.Version instead of executing a PowerShell script, simplifying and making the version detection more robust.

PR Context

Fixes #1676

PR Checklist

@adityapatwardhan

Copy link
Copy Markdown
Member Author

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 1 pipeline(s).

@adityapatwardhan

Copy link
Copy Markdown
Member Author

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 1 pipeline(s).

Comment thread src/code/ServerFactory.cs
_psVersion = ps.AddScript("$PSVersionTable").Invoke<Hashtable>()[0]["PSVersion"].ToString();
}

_psVersion = System.Management.Automation.Runspaces.Runspace.DefaultRunspace.Version.ToString();

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we potentially need the null coalescing operator for any of these properties?

@anamnavi Anam Navied (anamnavi) left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, left a comment

@adityapatwardhan
Aditya Patwardhan (adityapatwardhan) merged commit 1884d13 into master Sep 5, 2025
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

WDAC blocking PSResourceGet because of Dot sourcing in Find-PSResource

2 participants